package com.ccp.dev.system.model;

import com.ccp.dev.core.basic.model.BaseModel;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 子系统管理 Model对象
 * @author y
 */
@Component
public class SubSystem extends BaseModel {
	/**
	 * 当前系统
	 */
	public static String CURRENT_SYSTEM="CURRENT_SYSTEM";
	/**
	 * 默认图标
	 */
	public static String DEFAULT_LOG="/styles/common/img/images/resicon/home.png";
	/**
	 * 默认子系统ID
	 */
	public final static String DEFAULT_SYSTEM_ID = "1";
	
	public static short isLocal_Y=1;
	public static short isLocal_N=0;

	/**
	 * 主键
	 */
	private String systemId;
	/**
	 * 系统名称
	 */
	private String sysName;
	/**
	 *  别名(系统中唯一)
	 */
	private String alias;
	/**
	 * 系统的图标
	 */
	private String logo;
	/**
	 * 系统首页地址
	 */
	private String defaultUrl;
	/**
	 * 备注
	 */
	private String memo;
	/**
	 * 创建人
	 */
	private String creator;
	/**
	 * 允许删除
	 */
	private Short allowDel=0;
	/**
	 * 选择组织架构
	 */
	private Short needOrg;
	/**
	 * 是否激活
	 */
	private Short isActive=1;
	/**
	 * 父系统，用于生成树
	 */
	private Long parentId=0L;
	/**
	 * 是否本地
	 */
	private Short isLocal=1;
	/**
	 * home页面
	 */
	private String homePage;

	List<SysRole> roleList;
	/**
	 * 前端下拉需要
	 */
	private  String name;
	/**
	 * 前端下拉需要
	 */
	private  String value;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getHomePage() {
		return homePage;
	}
	public void setHomePage(String homePage) {
		this.homePage = homePage;
	}
	public Short getIsLocal() {
		return isLocal;
	}
	public void setIsLocal(Short isLocal) {
		this.isLocal = isLocal;
	}

	public String getSystemId() {
		return systemId;
	}

	public void setSystemId(String systemId) {
		this.systemId = systemId;
	}

	public void setSysName(String sysName) {
		this.sysName = sysName;
	}

	public String getSysName() {
		return sysName;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public String getAlias() {
		return alias;
	}

	public void setLogo(String logo) {
		this.logo = logo;
	}

	public String getLogo() {
		if(logo!=null){
			return logo;
		}else{
			return DEFAULT_LOG;
		}
	}

	public void setDefaultUrl(String defaultUrl) {
		this.defaultUrl = defaultUrl;
	}

	public String getDefaultUrl() {
		return defaultUrl;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public String getMemo() {
		return memo;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	public String getCreator() {
		return creator;
	}

	public void setAllowDel(Short allowDel) {
		this.allowDel = allowDel;
	}

	public Short getAllowDel() {
		return allowDel;
	}

	public void setNeedOrg(Short needOrg) {
		this.needOrg = needOrg;
	}

	public Short getNeedOrg() {
		return needOrg;
	}

	public void setIsActive(Short isActive) {
		this.isActive = isActive;
	}

	public Short getIsActive() {
		return isActive;
	}	
	
	public List<SysRole> getRoleList() {
		return roleList;
	}
	
	public void setRoleList(List<SysRole> roleList) {
		this.roleList = roleList;
	}
	
	public Long getParentId()
	{
		return parentId;
	}

	public void setParentId(Long parentId)
	{
		this.parentId = parentId;
	}

	@Value("${loginSystem.cookie.name}")
	public void setCurrentSystem(String currentSystem) {
		CURRENT_SYSTEM = currentSystem;
	}

	@Override
	 public int hashCode() {
		 HashCodeBuilder has=new HashCodeBuilder();
		 has.append(this.systemId);
		 return has.toHashCode();
	 }
	@Override
	public boolean equals(Object object) 
	{
		if (!(object instanceof SubSystem)) 
		{
			return false;
		}
		SubSystem rhs = (SubSystem) object;
		return new EqualsBuilder()
		.append(this.systemId, rhs.systemId)
		.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this)
				.append("systemId", systemId)
				.append("sysName", sysName)
				.append("alias", alias)
				.append("logo", logo)
				.append("defaultUrl", defaultUrl)
				.append("memo", memo)
				.append("createTime", createTime)
				.append("creator", creator)
				.append("allowDel", allowDel)
				.append("needOrg", needOrg)
				.append("isActive", isActive)
				.append("parentId", parentId)
				.append("isLocal", isLocal)
				.append("homePage", homePage)
				.append("createBy", createBy)
				.append("createTime", createTime)
				.append("updateTime", updateTime)
				.append("updateBy", updateBy)
				.append("tenantId", tenantId)
				.toString();
	}
}